<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cookie;

class AdminAuth
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        if (!Auth::check()) {
            return redirect('admin/login');
        } else {
            $adminid = $request->cookie('adminid');
            if ($adminid != Auth::id()) {
                return redirect('admin/login');
            }
        }

        return $next($request);
    }
}
